#Replication power calculation

setwd("Location of unzipped files")

#Installing/loading packages
if(!require(devtools)) install.packages("devtools")
library(devtools)
devtools::install_github("m-freitag/cjpowR")
if(!require(foreign)) install.packages("foreign")

library(cjpowR)
library(foreign)

# Estimating  the minimum required effective sample size:
est02_7 = cjpowr_amce(amce = 0.02, power = 0.7, levels = 2)
est03_7 = cjpowr_amce(amce = 0.03, power = 0.7, levels = 2)
est04_7 = cjpowr_amce(amce = 0.04, power = 0.7, levels = 2)
est05_7 = cjpowr_amce(amce = 0.05, power = 0.7, levels = 2)
est06_7 = cjpowr_amce(amce = 0.06, power = 0.7, levels = 2)
est07_7 = cjpowr_amce(amce = 0.07, power = 0.7, levels = 2)
est08_7 = cjpowr_amce(amce = 0.08, power = 0.7, levels = 2)
est09_7 = cjpowr_amce(amce = 0.09, power = 0.7, levels = 2)
est10_7 = cjpowr_amce(amce = 0.1, power = 0.7, levels = 2)

est02_8 = cjpowr_amce(amce = 0.02, power = 0.8, levels = 2)
est03_8 = cjpowr_amce(amce = 0.03, power = 0.8, levels = 2)
est04_8 = cjpowr_amce(amce = 0.04, power = 0.8, levels = 2)
est05_8 = cjpowr_amce(amce = 0.05, power = 0.8, levels = 2)
est06_8 = cjpowr_amce(amce = 0.06, power = 0.8, levels = 2)
est07_8 = cjpowr_amce(amce = 0.07, power = 0.8, levels = 2)
est08_8 = cjpowr_amce(amce = 0.08, power = 0.8, levels = 2)
est09_8 = cjpowr_amce(amce = 0.09, power = 0.8, levels = 2)
est10_8 = cjpowr_amce(amce = 0.1, power = 0.8, levels = 2)

est02_9 = cjpowr_amce(amce = 0.02, power = 0.9, levels = 2)
est03_9 = cjpowr_amce(amce = 0.03, power = 0.9, levels = 2)
est04_9 = cjpowr_amce(amce = 0.04, power = 0.9, levels = 2)
est05_9 = cjpowr_amce(amce = 0.05, power = 0.9, levels = 2)
est06_9 = cjpowr_amce(amce = 0.06, power = 0.9, levels = 2)
est07_9 = cjpowr_amce(amce = 0.07, power = 0.9, levels = 2)
est08_9 = cjpowr_amce(amce = 0.08, power = 0.9, levels = 2)
est09_9 = cjpowr_amce(amce = 0.09, power = 0.9, levels = 2)
est10_9 = cjpowr_amce(amce = 0.1, power = 0.9, levels = 2)

# Combining data frames:
power_combined <- rbind(est02_7, est02_8, est02_9, est03_7, est03_8, est03_9, est04_7, est04_8, est04_9, est05_7, est05_8, est05_9, est06_7, est06_8, est06_9, est07_7, est07_8, est07_9, est08_7, est08_8, est08_9, est09_7, est09_8, est09_9, est10_7, est10_8, est10_9)

# Defining estimates:
power_combined$estimate <- power_combined$amce
power_combined$estimate[power_combined$estimate == 0.02] <- 0.22
power_combined$estimate[power_combined$estimate == 0.03] <- 0.33
power_combined$estimate[power_combined$estimate == 0.04] <- 0.44
power_combined$estimate[power_combined$estimate == 0.05] <- 0.55
power_combined$estimate[power_combined$estimate == 0.06] <- 0.66
power_combined$estimate[power_combined$estimate == 0.07] <- 0.77
power_combined$estimate[power_combined$estimate == 0.08] <- 0.88
power_combined$estimate[power_combined$estimate == 0.09] <- 0.99
power_combined$estimate[power_combined$estimate == 0.10] <- 1.10

# Exporting data:
write.dta(power_combined, "power_combined.dta")




